package jp.tkym.labs.store.ormap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class OrMapObjectProvider {
	private static final OrMapObjectProvider singleton = new OrMapObjectProvider();
	
	private OrMapObjectFactory factory;
	private Map<Class<?>, OrMapObject> map;
	
	private OrMapObjectProvider(){
		factory = new OrMapObjectFactory();
		map = new ConcurrentHashMap<Class<?>, OrMapObject>();
	}
	
	public static OrMapObjectProvider getInstance(){
		return singleton;
	}
	
	public <T> OrMapObject get(Class<T> cls){
		OrMapObject target = map.get(cls);
		if(target == null){
			target = factory.create(cls);
			map.put(cls, target);
		}
		return target;
	}
}
